import { reqDeleteAttr, reqGetArrtInfoList } from '@/api/product/attr';
const state = {
    attrInfoList: [],
    levelOneId: "",
    levelTwoId: "",
    levelThreeId: ""
}
const mutations = {
    RECEIVE_ATTRINFOLIST(state, data) {
        state.attrInfoList = data
    },
    RECEIVE_ID(state, {levelOneId, levelTwoId, levelThreeId }) {
        state.levelOneId = levelOneId
        state.levelTwoId = levelTwoId
        state.levelThreeId = levelThreeId
    }
}
const actions = {
    async getAttrInfoList({ commit }, { levelOneId, levelTwoId, levelThreeId }) {
        const result = await reqGetArrtInfoList(levelOneId, levelTwoId, levelThreeId)
        let data = result.data
        if (result.code == 200) {
            commit("RECEIVE_ATTRINFOLIST", data)
        }
    },
    async deleteAttr({ commit }, id) {
        const result = await reqDeleteAttr(id)
        if (result.code == 200) {
            return 'ok'
        } else {
            return Promise(new Error("faile"))
        }
    },
    getAttrInfoId({ commit }, { levelOneId, levelTwoId, levelThreeId }) {
        commit("RECEIVE_ID", { levelOneId, levelTwoId, levelThreeId })
    },
}
export default {
    namespaced: true,
    state, mutations, actions
}